﻿namespace YidanSoft.Library.EditorUtility.Collections
{
    using System;
    using System.Drawing;
    using System.Reflection;
    using YidanSoft.Library.EditorUtility.Menus;

    public class MenuCommandCollection : CollectionWithEvents
    {
        protected Brush _extraBackBrush = null;
        protected Color _extraBackColor = SystemColors.ActiveCaption;
        protected Font _extraFont = SystemInformation.MenuFont;
        protected string _extraText = "";
        protected Brush _extraTextBrush = null;
        protected Color _extraTextColor = SystemColors.ActiveCaptionText;

        public MenuCommand Add(MenuCommand value)
        {
            base.List.Add(value);
            return value;
        }

        public void AddRange(MenuCommand[] values)
        {
            foreach (MenuCommand command in values)
            {
                this.Add(command);
            }
        }

        public bool Contains(MenuCommand value)
        {
            return base.List.Contains(value);
        }

        public int IndexOf(MenuCommand value)
        {
            return base.List.IndexOf(value);
        }

        public void Insert(int index, MenuCommand value)
        {
            base.List.Insert(index, value);
        }

        public void Remove(MenuCommand value)
        {
            base.List.Remove(value);
        }

        public bool VisibleItems()
        {
            foreach (MenuCommand command in base.List)
            {
                if (command.Visible && (command.Text != "-"))
                {
                    if ((command.MenuCommands.Count <= 0) || command.MenuCommands.VisibleItems())
                    {
                        return true;
                    }
                    continue;
                }
            }
            return false;
        }

        public Brush ExtraBackBrush
        {
            get
            {
                return this._extraBackBrush;
            }
            set
            {
                this._extraBackBrush = value;
            }
        }

        public Color ExtraBackColor
        {
            get
            {
                return this._extraBackColor;
            }
            set
            {
                this._extraBackColor = value;
            }
        }

        public Font ExtraFont
        {
            get
            {
                return this._extraFont;
            }
            set
            {
                this._extraFont = value;
            }
        }

        public string ExtraText
        {
            get
            {
                return this._extraText;
            }
            set
            {
                this._extraText = value;
            }
        }

        public Brush ExtraTextBrush
        {
            get
            {
                return this._extraTextBrush;
            }
            set
            {
                this._extraTextBrush = value;
            }
        }

        public Color ExtraTextColor
        {
            get
            {
                return this._extraTextColor;
            }
            set
            {
                this._extraTextColor = value;
            }
        }

        public MenuCommand this[int index]
        {
            get
            {
                return (base.List[index] as MenuCommand);
            }
        }

        public MenuCommand this[string text]
        {
            get
            {
                foreach (MenuCommand command in base.List)
                {
                    if (command.Text == text)
                    {
                        return command;
                    }
                }
                return null;
            }
        }
    }
}

